var rootPath = getRootPath();

$(document).ready(function(){
	var potentialUserId = 10000001
	var positionId = 601;
	
	$.ajax({
		method : 'get',
		url : rootPath+'/wechat/api/counselor/selectCounselor?potentialUserId='+potentialUserId+'&positionId='+positionId, 
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			alert("连接服务器错误!");
		},
		success : function(resultData){
			
			var wholeHtml = ''; 
			
			$.each(resultData,function(counselorIndex,counselorObj){
				
				var counselorHtml = '';
				
				var n = counselorObj.userId;
				
				counselorHtml = counselorHtml   + '<form role="form">'
												+ '<div class="col-md-4 form-group">'
												+ '<ul><li id="ss'+ n +'">'
												+   '<img class="img-circle" src="./../qiankun/img/1.png" alt="头像图片" title="头像" style="width:80%"/>'
												+ 	'<script type="text/javascript" src="../../qiankun/js/index.js"></script>'
												+     '<p><span>'+ counselorObj.userName +'</span></p>'
												+	  '<input style="display:none" type="text" id="potentialUserId'+ n +'" name="potentialUserId1" class="form-control" value="'+ counselorObj.potentialUserId +'">'
												+	  '<input style="display:none" type="text" id="userId'+ n +'" name="userId1" class="form-control" value="'+ counselorObj.userId +'">'
												+	  '<input style="display:none" type="text" id="positionId'+ n +'" name="positionId1" class="form-control" value="'+ counselorObj.positionId +'">'		
												+ '</li></ul>'
												+ '</div>'
												+ '</form>'
												+ '<script type="text/javascript">'
												+ '$("#ss'+ n +'").click(function () {'
												+ '$("#potentialUserId").val($("#potentialUserId'+ n +'").val());'
												+ '$("#userId").val($("#userId'+ n +'").val());'
												+ '$("#positionId").val($("#positionId'+ n +'").val());'
												+ '$(this).toggleClass("selected");'
												+ ' counter();'
												+ '});'
												+ '</script>'
				
				wholeHtml += counselorHtml;
				
			});
			    wholeHtml = wholeHtml + '<input id="sel" type="button"  data-toggle="modal" data-target="#myModal"  value="确认" class="btn btn-primary btn-lg btn-block" />'
			$("#counselors").append(wholeHtml);
		}
	});
		$('#modalCancel').click(function(){
			window.location.reload();
		});
		
		$('#modalSure').click(function(){
			var data={
			potentialUserId:"",
			userId:"",
			positionId:"",
	    }; 
	    
	    data.potentialUserId = $.trim($("#potentialUserId").val()); 
	    data.userId = $.trim($("#userId").val()); 
	    data.positionId = $.trim($("#positionId").val()); 
	    
	    
		$.ajax({
			type : 'POST',
			url : rootPath+'/wechat/api/counselors',
			contentType:"application/json",
			data: JSON.stringify(data),
			error:function(XMLHttpRequest, ajaxOptions, thrownError){
				alert("失败");
			},
			success : function(data){
				alert("成功");
			}
		});
	  });
})
